# testjson.py
import asyncio
import json
import os
from khl import Bot, MessageTypes, api

# 加载配置
CFG = json.load(open(os.path.join(os.path.dirname(__file__), 'config.json'), 'r', encoding='utf-8'))

async def test_send_message():
    bot = Bot(token=CFG['bot_token'])
    print(f"尝试向频道 {CFG['panel_channel_id']} 发送测试消息...")
    try:
        response = await bot.client.gate.exec_req(
            api.Message.create(
                channel_id=CFG['panel_channel_id'],
                content="这是一个来自Bot的测试消息！",
                type=MessageTypes.KMD
            )
        )
        print(f"消息发送成功！API响应: {response}")
    except Exception as e:
        print(f"发送消息失败: {e}")
    finally:
        await bot.shutdown() # 使用 Bot 的 shutdown 方法来优雅关闭
        print("Bot shutdown complete.")

if __name__ == '__main__':
    asyncio.run(test_send_message())
